#include "stdio.h"
#include "math.h"

int main(void)
{
    // 3、求π的值，已知π/4≈1-1/3+1/5-1/7+……，计算至某项的绝对值小于1E-6为止。（没有明确范围的循环）

    double sum = 0, term = 1;
    double jiaxiang = 1;
    int i = 1;
    while (fabs((term * (1 / (double)i))) >= 1e-6)
    {
        sum += term * (1.0 / (double)i);
        term = -term;
        i += 2;
    }
    printf("pi=%lf\n", 4.0 * sum);
    return 0;
}